<template>
    <div>
        <h1>医生新增</h1>
        <table class="table">
            <tbody>
                <tr>
                    <td>医生名称</td>
                    <td><input type="text" v-model="data.DocName"></td>
                </tr>
                <tr>
                    <td>医生头像</td>
                    <td>
                        <input type="file" @change="Tu">
                        <img :src="'https://localhost:7087/'+data.DocImg" style="height: 60px; width: 60px;">
                    </td>
                </tr>

                <tr>
                    <td>科室</td>
                    <td>
                        <select v-model="data.DepId">
                            <option value="0">请选择</option>
                            <option v-for="a in bang" :value="a.DepId">{{a.DepName}}</option>
                        </select>
                    </td>
                </tr>


                <tr>
                    <td>创建日期</td>
                    <td><input type="date" v-model="data.DocTime"></td>
                </tr>
                <tr>
                    <td></td>
                    <td><input type="button" value="新增" @click="Add"></td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">

import { ref,onMounted } from 'vue';
import axios from 'axios';
import { useRouter } from 'vue-router';
const router = useRouter()

onMounted(()=>{
    xia()
})

//下拉框
const bang = ref([{
    "DepId": 1,
    "DepName": "脑科",
    "DepNum": "120",
    "DepMiao": "术业有专攻，全是教授",
    "DepDate": "2025-05-01T00:00:00",
    "DepIsDelete": true
}])
const xia = ()=>{
    axios.get('https://localhost:7087/api/Bing/Xia').then(res=>{
        bang.value = res.data;
    })
}

//图片
const Tu =(e:any)=>{
    var f = e.target.files[0];
    var fd = new FormData();
    fd.append("file",f);
    axios.post('https://localhost:7087/api/Files/Tu',fd).then(res=>{
        data.value.DocImg=res.data;
    })
}

const data = ref({
    "DocId": 0,
  "DocName": "",
  "DocImg": "",
  "DepId": 0,
  "DocTime": ""
})

const Add = ()=>{
    if(data.value.DocName==""){
        alert('名称不能为空')
        return;
    }
    axios.post('https://localhost:7087/api/Doctor/DocAdd',data.value).then(res=>{
        if(res.data>0){
            alert('新增成功');
            router.push({path:"/DocShow"});
        }
        else{
            alert('新增失败')
        }
    })
}


</script>

<style scoped>

</style>